package com.person.leetcode.editor.cn;

/**
 * TODO 根本做不出来
 * 5.最长回文子串
 * 2022-04-26 16:40:59
 **/
public class Sequence_0005_LongestPalindromicSubstring {
    public static void main(String[] args) {
        Solution solution = new Sequence_0005_LongestPalindromicSubstring().new Solution();
        StringBuilder builder = new StringBuilder("12345");
        System.out.println("builder "+builder);
        StringBuilder reverse = builder.reverse();
        System.out.println("builder "+builder);
        System.out.println("reverse "+reverse);
        builder.setLength(0);
        System.out.println("builder "+builder);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        //aba 3
        //abba 4
        public String longestPalindrome(String s){
            if (s == null || s.length() < 1) { return ""; }
            int max=0,start=0,end=0;
            for (int i = 0; i < s.length(); i++) {
                int len1 = expand(s, i, i);
                int len2 = expand(s, i, i + 1);
                int curMax = Math.max(len1, len2);
                if (curMax>max){
                    max = curMax;
                    start = i - (max-1)/2;
                    end = i + max/2;
                }
            }
            return s.substring(start,end+1);
        }
        private int expand(String s,int left,int right){
            while(left >= 0 && right <s.length() && s.charAt(left)==s.charAt(right)){

                    left --;
                    right ++;

            }
            return right-left-1;
        }

    }

//leetcode submit region end(Prohibit modification and deletion)

}
